package com.lagouedu.rabbitmq_demo.mq;

import com.lagouedu.rabbitmq_demo.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OrderListenner {

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = "queue.dlx")
    public void consumeDlx(Map message){
        // 首先判断订单是否支付
        int orderId = orderService.getOrderStatus((Integer) message.get("orderId"));
        // 如果订单未支付则取消订单
        if (orderId == 0) {
            orderService.updateOrderStatus((Integer) message.get("orderId"),2);
        }
        System.out.println(message);
    }
}
